< previous page page_699 next page >

Page 699
2. Execute the query using ADO to obtain a recordset.
3. Send the contents of the recordset back to the user's browser.
The code for DBSEARCH.ASP, shown in Listing 31.4, uses the Like statement in the SQL query.
Listing 31.4 ASPDEMO.ZIPDBSEARCH.ASP Performs the Database Search
<HTML><BODY>
<%
   Dim cn
   Dim rs
   Dim sSQL
   Dim sSearchString

   'GET THE SEARCH STRING FROM THE FORM
   sSearchString = Request.Form("txtSearch")

   If sSearchString = "" Then
      Response.Write ("No search string entered!")
      Response.End
   End If

   'CONNECT TO THE DATABASE AND PERFORM THE SEARCH
   Set cn = Server.CreateObject("ADODB.Connection")
        cn.Open "DSN=BIBLIO"

   sSQL = "SELECT * FROM AUTHORS WHERE AUTHOR LIKE "
   sSQL = sSQL & "'" & sSearchString & "%' ORDER BY AUTHOR"

   Set rs = cn.Execute(sSQL)

%>
<TABLE BORDER=1>
<TR>Author's Name</TR>
<%

   'DISPLAY THE RESULTS IN A TABLE
   While Not rs.EOF
      Response.Write ("<TR><TD>")
      Response.Write rs.Fields("Author")
      Response.Write ("<TD></TR>")
                rs.MoveNext
   Wend

   rs.Close
   cn.Close
   Set rs = Nothing
   Set cn = Nothing
%>
</TABLE>
</BODY></HTML>

 
< previous page page_699 next page >